<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <label class="el-form-item-label">容器id</label>
        <el-input v-model="query.containerId" clearable placeholder="容器id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">容器类型</label>
        <el-input v-model="query.containerType" clearable placeholder="容器类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">对应的储位编号</label>
        <el-input v-model="query.storageId" clearable placeholder="对应的储位编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" :plain="true" />
      </div>
      <crudOperation :permission="permission" :plain="true" />
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="containerId" label="容器id" />
        <el-table-column prop="containerType" label="容器类型" />
        <el-table-column label="台车状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              active-color="#409EFF"
              :active-value="0"
              :inactive-value="1"
              inactive-color="#F56C6C"
              @change="changeEnabled(scope.row, scope.row.status)"
            />
          </template>
        </el-table-column>
        <el-table-column prop="containerDescription" label="容器描述" />
        <el-table-column prop="storageId" label="对应的储位编号" />
        <!-- <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="更新时间" /> -->
        <!-- <el-table-column v-if="checkPer(['admin','wcsContainer:edit','wcsContainer:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWcsContainer from '@/api/work/wcsContainer'
import { editContainerStatus } from '@/api/work/wcsContainer'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, containerId: null, containerType: null, containerDescription: null, storageId: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'WcsContainer',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'WcsContainerController', url: 'api/wcsContainer', idField: 'id', sort: 'id,desc', crudMethod: { ...crudWcsContainer },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: true,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'wcsContainer:add'],
        edit: ['admin', 'wcsContainer:edit'],
        del: ['admin', 'wcsContainer:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'containerId', display_name: '容器id' },
        { key: 'containerType', display_name: '容器类型' },
        { key: 'storageId', display_name: '对应的储位编号' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    async changeEnabled(data, val) {
      let text
      if (val === 1) {
        text = '禁用'
      } else {
        text = '启用'
      }
      const res = await editContainerStatus(data.containerId)
      if (res.code === 200) {
        this.$message.success(text + res.message)
        this.crud.toQuery()
      } else {
        this.crud.toQuery()
        this.$message.warning(text + res.message)
      }
    }
  }
}
</script>

<style scoped>

</style>
